<template>
  <div class="wrap">
    <span @click="click">
      <svg-icon :icon-class="isFullscreen ? 'exit-fullscreen' : 'fullscreen'" />
    </span>
  </div>
</template>

<script>
import screenfull from "screenfull"

export default {
  name: "Screenfull",
  data() {
    return {
      isFullscreen: false
    }
  },
  mounted() {
    this.init()
  },
  beforeDestroy() {
    this.destroy()
  },
  methods: {
    click() {
      if (!screenfull.enabled) {
        this.$message({
          message: "you browser can not work",
          type: "warning"
        })
        return false
      }
      screenfull.toggle()
    },
    change() {
      this.isFullscreen = screenfull.isFullscreen
    },
    init() {
      if (screenfull.enabled) {
        screenfull.on("change", this.change)
      }
    },
    destroy() {
      if (screenfull.enabled) {
        screenfull.off("change", this.change)
      }
    }
  }
}
</script>

<style scoped lang="scss">
.wrap {
  cursor: pointer;
  height: $navbarHeight;
  width: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  // margin: 0 !important;
}
.screenfull-svg {
  display: inline-block;
  cursor: pointer;
  fill: #5a5e66;
  width: 20px;
  height: 20px;
}
</style>
